package fun.chutianshu.eescore_full.service.impl;

import fun.chutianshu.eescore_full.entity.Department;
import fun.chutianshu.eescore_full.entity.Profession;
import fun.chutianshu.eescore_full.dao.ProfessionDao;
import fun.chutianshu.eescore_full.service.ProfessionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 专业表(Profession)表服务实现类
 *
 * @author makejava
 * @since 2021-04-23 16:10:23
 */
@Service("professionService")
public class ProfessionServiceImpl implements ProfessionService {
    @Resource
    private ProfessionDao professionDao;

    @Override
    public Profession queryProAndDeptByProId(Integer proId) {
        return professionDao.selectProfessionAndDepartmentByProId(proId);
    }

    @Override
    public Department queryDepartmentById(Integer proId) {
        return professionDao.queryDepartmentById(proId);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param proId 主键
     * @return 实例对象
     */
    @Override
    public Profession queryById(Integer proId) {
        return this.professionDao.queryById(proId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Profession> queryAllByLimit(int offset, int limit) {
        return this.professionDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param profession 实例对象
     * @return 实例对象
     */
    @Override
    public Profession insert(Profession profession) {
        this.professionDao.insert(profession);
        return profession;
    }

    /**
     * 修改数据
     *
     * @param profession 实例对象
     * @return 实例对象
     */
    @Override
    public Profession update(Profession profession) {
        this.professionDao.update(profession);
        return this.queryById(profession.getProId());
    }

    /**
     * 通过主键删除数据
     *
     * @param proId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer proId) {
        return this.professionDao.deleteById(proId) > 0;
    }
}
